package Platform.WandaBIM6D;

import Base.*;
import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by Alain on 2016/3/9.
 */
@SuppressWarnings("unused")
public class BIM6D extends TestBase {
    private static TestBase TB = new TestBase();
    private static DataFactory DF = new DataFactory();
    private static String requestURL, response=null, requestBody=null, responseData=null,
                    sceneId             = DF.getCellValue("WandaBIM6D", "sceneId"),
                    elementId           = DF.getCellValue("WandaBIM6D", "elementId"),
                    startTime           = DF.getCellValue("WandaBIM6D", "startTime"),
                    endTime             = DF.getCellValue("WandaBIM6D", "endTime"),
                    projectId           = DF.getCellValue("WandaBIM6D", "projectId"),
                    projectVersionId    = DF.getCellValue("WandaBIM6D", "projectVersionId"),
                    collisionId         = DF.getCellValue("WandaBIM6D", "collisionId"),
                    pageNo              = DF.getCellValue("WandaBIM6D", "pageNo"),
                    pageSize            = DF.getCellValue("WandaBIM6D", "pageSize"),
                    comparisonId        = DF.getCellValue("WandaBIM6D", "comparisonId"),
                    viewPointId         = DF.getCellValue("WandaBIM6D", "viewPointId");

    /*01.获取构件属性
    GET  https://bim.wanda.cn/sixD/{projectId}/{projectVersionId}/property?sceneId={sceneId}&elementId={elementId}
    参数名             是否必选        类型      描述
    elementId	        是	 	                 构件ID
    projectId	        是	 	                 项目ID
    projectVersionId	是	 	                 项目版本ID
    sceneId	            是	 	                 场景ID*/
    public String getElementProperty(){
        requestURL = "/sixD/"+projectId+"/"+projectVersionId+"/property?sceneId=" + sceneId + "&elementId=" + elementId;

        //send request
        try {
            response = TB.apiResponse(requestURL, "GET");

        } catch (Exception e) {
            log.info(e);
        }

        return  response;
    }

    /*02.获取构件成本信息
    GET  https://bim.wanda.cn/sixD/{projectId}/{projectVersionId}/cost?sceneId={sceneId}&elementId={elementId}
    参数名             是否必选        类型      描述
    elementId	        是	 	                 构件ID
    projectId	        是	 	                 项目ID
    projectVersionId	是	 	                 项目版本ID
    sceneId	            是	 	                 场景ID*/
    public String getElementCost(){
        requestURL = "/sixD/"+projectId+"/"+projectVersionId+"/cost/edo?sceneId=" + sceneId + "&elementId=" + elementId;

        //send request
        try {
            response = TB.apiResponse(requestURL, "GET");

        } catch (Exception e) {
            log.info(e);
        }

        return  response;
    }

    /*03.获取项目计划属性
    GET  https://bim.wanda.cn/sixD/{projectId}/{projectVersionId}/plan/edo?sceneId={sceneId}&elementId={elementId}
    参数名               是否必选    类型      描述
    elementId	        是	 	                 构件ID
    projectId	        是	 	                 项目ID
    projectVersionId	是	 	                 项目版本ID
    sceneId	            是	 	                 场景ID*/
    public String getElementPlan(){
        requestURL = "/sixD/"+projectId+"/"+projectVersionId+"/plan/edo?sceneId="+sceneId+"&elementId="+elementId;

        //send request
        try {
            response = TB.apiResponse(requestURL, "GET");

        } catch (Exception e) {
            log.info(e);
        }

        return  response;
    }

    /*04.获取视点列表
    GET  https://bim.wanda.cn/sixD/{projectId}/viewPoint
    参数名               是否必选    类型      描述
    projectId	           是	 	           项目ID*/
    public String getViewPointList(){
        String checkResult[] = {"projectId", "id", "name", "viewPoint", "createTime"};
        requestURL = "/sixD/"+projectId+"/viewPoint";

        //send request
        try {
            response = TB.apiResponse(requestURL, "GET");

            TB.checkResponseValue(checkResult);
        } catch (Exception e) {
            log.info(e);
        }

        return  response;
    }

    /*05.创建视点
    POST  https://bim.wanda.cn/sixD/{projectId}/viewPoint
    参数名               是否必选    类型      描述
    projectId	           是	 	           项目ID*/
    public String createViewPoint(){
        requestURL = "/sixD/"+projectId+"/viewPoint";
        requestBody = "{\"name\": \"自动化视点创建\"," +
                "       \"viewPoint\": \"{\"camera\":{\"x\":1.222222, \"y\": 2.11111, \"z\": 3.1111}," +
                "       \"direction\":{\"x\":11.222222, \"y\": 22.11111, \"z\": 32.1111}," +
                "       \"up\":{\"x\":6.222222,\"y\": 5.11111, \"z\": 9.1111}}\",}";
        //send request
        try {
            response = TB.apiResponse(requestURL, "POST", requestBody);

        } catch (Exception e) {
            log.info(e);
        }
        return  response;
    }

    /*06.重命名视点
    PUT  https://bim.wanda.cn/sixD/{projectId}/viewPoint/{viewPointId}
    参数名               是否必选    类型      描述
    projectId	           是	 	           项目ID
    viewPointId	           是	 	           视点ID*/
    public String renameViewPoint(){
        requestURL = "/sixD/"+projectId+"/viewPoint/"+viewPointId;
        requestBody = "{" +
                "           \"name\": \"视点新名称\"," +
                "      }";
        //send request
        try {
            response = TB.apiResponse(requestURL, "PUT", requestBody);

        } catch (Exception e) {
            log.info(e);
        }

        return  response;
    }

    /*07.删除视点
    DELETE  https://bim.wanda.cn/sixD/{projectId}/viewPoint/{viewPointId}
    参数名               是否必选    类型      描述
    projectId	           是	 	           项目ID
    viewPointId	           是	 	           视点ID*/
    public String deleteViewPoint(){
        requestURL = "/sixD/"+projectId+"/viewPoint/"+viewPointId;

        //send request
        try {
            response = TB.apiResponse(requestURL, "DELETE");

        } catch (Exception e) {
            log.info(e);
        }

        return  response;
    }

    /*08.设置碰撞检查
    POST  https://bim.wanda.cn/sixD/{projectId}/{projectVersionId}/collision/setting
    参数名               是否必选    类型      描述
    projectId	           是	 	           项目ID
    projectVersionId	   是	 	           项目版本ID*/
    public String setCollision(){
        requestURL = "/sixD/"+projectId+"/"+projectVersionId+"/collision/setting";

        String[] categoryList = new String[4];
        for (int i=0; i<4; i++){
            categoryList[i] = "-00025";
        }

        CollisionFile CF1 = new CollisionFile();
        CF1.setCategories(categoryList);
        CF1.setSpeciality("AA");

        CollisionFile CF2 = new CollisionFile();
        CF2.setCategories(categoryList);
        CF2.setSpeciality("AB");

        CollisionFile CF3 = new CollisionFile();
        CF3.setCategories(categoryList);
        CF3.setSpeciality("AC");

        CollisionFile CF4 = new CollisionFile();
        CF4.setCategories(categoryList);
        CF4.setSpeciality("AD");

        List<CollisionFile> CollisionList1 = new ArrayList<CollisionFile>();
        CollisionList1.add(CF1);
        CollisionList1.add(CF2);

        List<CollisionFile> CollisionList2 = new ArrayList<CollisionFile>();
        CollisionList2.add(CF3);
        CollisionList2.add(CF4);

        MultipleCollisionFile<CollisionFile> CMF = new MultipleCollisionFile<CollisionFile>();
        CMF.setName("碰撞检测");
        CMF.setFloor("all");
        CMF.setListFileA(CollisionList1);
        CMF.setListFileB(CollisionList2);

        requestBody = JsonUtils.toJson(CMF);
        //send request
        try {
            response = TB.apiResponse(requestURL, "POST", requestBody);

        } catch (Exception e) {
            log.info(e);
        }

        return  response;
    }

    /*09.获取指定的碰撞任务
    GET  https://bim.wanda.cn/sixD/{projectId}/{projectVersionId}/collision/setting?collisionId={collisionId}
    参数名               是否必选    类型      描述
    projectId	            是	 	           项目ID
    projectVersionId	    是	 	           项目版本ID
    collisionId	            是	 	           碰撞任务ID*/
    public String getCollision(){
        requestURL = "/sixD/"+projectId+"/"+projectVersionId+"/collision/setting?collisionId="+collisionId;

        //send request
        try {
            response = TB.apiResponse(requestURL, "GET");

        } catch (Exception e) {
            log.info(e);
        }

        return  response;
    }

    /*10.获取碰撞任务列表
    GET  https://bim.wanda.cn/sixD/{projectId}/{projectVersionId}/collision/setting/list
    参数名               是否必选    类型      描述
    projectId	            是	 	           项目ID
    projectVersionId	    是	 	           项目版本ID*/
    public String getCollisionList(){
        requestURL = "/sixD/"+projectId+"/"+projectVersionId+"/collision/setting/list";

        //send request
        try {
            response = TB.apiResponse(requestURL, "GET");

        } catch (Exception e) {
            log.info(e);
        }

        return  response;
    }

    /*11.获取碰撞点列表
    GET  https://bim.wanda.cn/sixD/{projectId}/{projectVersionId}/{collisionId}/point?pageNo={pageNo}&pageSize={pageSize}
    参数名               是否必选    类型      描述
    projectId	            是	 	           项目ID
    projectVersionId	    是	 	           项目版本ID
    collisionId	            是	 	           碰撞任务ID
    pageNo	                否	 	           页码，默认1
    pageSize	            否	 	           每页显示几条数据，默认10条*/
    public String getCollisionPoint(){
        requestURL = "/sixD/"+projectId+"/"+projectVersionId+"/"+collisionId+"/point?";

        if (StringUtils.isNotEmpty(pageNo))
            requestURL = TB.getURL(requestURL) + "pageNo=" + pageNo;
        if (StringUtils.isNotEmpty(pageSize))
            requestURL = TB.getURL(requestURL) + "pageSize=" + pageSize;
        //send request
        try {
            response = TB.apiResponse(requestURL, "GET");

        } catch (Exception e) {
            log.info(e);
        }

        return  response;
    }

    /*12.获取模型对比结果
    GET  https://bim.wanda.cn/sixD/{projectId}/{projectVersionId}/comparison/result?comparisonId={comparisonId}
    参数名               是否必选    类型      描述
    projectId	            是	 	           项目ID
    projectVersionId	    是	 	           项目版本ID
    comparisonId	        是	 	           对比ID*/
    public String getComparisonResult(){
        requestURL = "/sixD/"+projectId+"/"+projectVersionId+"/comparison/result?comparisonId="+comparisonId;

        //send request
        try {
            response = TB.apiResponse(requestURL, "GET");

        } catch (Exception e) {
            log.info(e);
        }

        return  response;
    }

    /*14.获取项目成本清单
   GET  https://bim.wanda.cn/sixD/{projectId}/{projectVersionId}/cost/summary
   参数名               是否必选    类型      描述
   projectId	            是	 	           项目ID
   projectVersionId	        是	 	           项目版本ID*/
    public String getProjectCostList(){
        requestURL = "/sixD/"+projectId+"/"+projectVersionId+"/cost/summary";

        //send request
        try {
            response = TB.apiResponse(requestURL, "GET");

        } catch (Exception e) {
            log.info(e);
        }

        return  response;
    }

    /*15.获取项目计划列表
   GET  https://bim.wanda.cn/sixD/{projectId}/{projectVersionId}/plan?startTime={startTime}&endTime={endTime}
   参数名               是否必选    类型       描述
   projectId	            是	 	           项目ID
   projectVersionId	        是	 	           项目版本ID
   startTime                否	 	           查询时间范围：开始
   endTime	                否	 	           查询时间范围：结束*/
    public String getProjectPlanList(){
        requestURL = "/sixD/"+projectId+"/"+projectVersionId+"/plan?";

        if (StringUtils.isNotEmpty(startTime))
            requestURL = TB.getURL(requestURL) + "startTime=" + startTime;
        if (StringUtils.isNotEmpty(endTime))
            requestURL = TB.getURL(requestURL) + "endTime=" + endTime;

        //send request
        try {
            response = TB.apiResponse(requestURL, "GET");

        } catch (Exception e) {
            log.info(e);
        }

        return  response;
    }

    /*16.获取批注
   GET  https://bim.wanda.cn/sixD/{projectId}/viewPoint/{viewPointId}/comment
   参数名               是否必选    类型       描述
   projectId	            是	 	           项目ID
   viewPointId  	        是	 	           视点ID*/
    public String getComment(){
        requestURL = "/sixD/"+projectId+"/viewPoint/"+viewPointId+"/comment";
        //send request
        try {
            response = TB.apiResponse(requestURL, "GET");

        } catch (Exception e) {
            log.info(e);
        }

        return  response;
    }

    /*17.创建批注
    POST  https://bim.wanda.cn/sixD/{projectId}/viewPoint/{viewPointId}/comment
    参数名               是否必选    类型       描述
    projectId	            是	 	           项目ID
    viewPointId  	        是	 	           视点ID*/
    public String createComment(){
        requestURL = "/sixD/"+projectId+"/viewPoint/"+viewPointId+"/comment";

        requestBody = "{" +"\"comments\":[\"commentA\", \"commentB\"]}";
        //send request
        try {
            response = TB.apiResponse(requestURL, "POST", requestBody);

        } catch (Exception e) {
            log.info(e);
        }

        return  response;
    }

    /*18.修改批注
    PUT  https://bim.wanda.cn/sixD/{projectId}/viewPoint/{viewPointId}/comment
    参数名               是否必选    类型       描述
    projectId	            是	 	           项目ID
    viewPointId  	        是	 	           视点ID*/
    public String modifyComment(){
        requestURL = "/sixD/"+projectId+"/viewPoint/"+viewPointId+"/comment";

        requestBody = "{" +"\"comments\":[\"newCommentA\", \"newCommentB\"]}";
        //send request
        try {
            response = TB.apiResponse(requestURL, "PUT", requestBody);

        } catch (Exception e) {
            log.info(e);
        }

        return  response;
    }

    /*19.删除批注
    DELETE  https://bim.wanda.cn/sixD/{projectId}/viewPoint/{viewPointId}/comment
    参数名               是否必选    类型       描述
    projectId	            是	 	           项目ID
    viewPointId  	        是	 	           视点ID*/
    public String deleteComment(){
        requestURL = "/sixD/"+projectId+"/viewPoint/"+viewPointId+"/comment";

        //send request
        try {
            response = TB.apiResponse(requestURL, "DELETE");

        } catch (Exception e) {
            log.info(e);
        }

        return  response;
    }
}
